package com.yanqu.road.server.cmd.union.trade;

import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.union.UnionTradeModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

//@Cmd(code = Protocol.S_UNION_TRADE_ROUTE_OPEN, desc = "开启路线")
public class TradeRouteOpenCmd  extends AbstractCommand {

    private int routeId;

    private int goodId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionTradeProto.RouteOpenReqMsg routeOpenReqMsg = UnionTradeProto.RouteOpenReqMsg.parseFrom(packet.getBytes());
        routeId = routeOpenReqMsg.getRouteId();
        goodId = routeOpenReqMsg.getGoodId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
            return;
        }
        ret = player.getModule(UnionTradeModule.class).openTradeRoute(routeId, goodId);

        UnionTradeProto.RouteOpenRespMsg.Builder routeOpenResp = UnionTradeProto.RouteOpenRespMsg.newBuilder();
        routeOpenResp.setRet(ret);
        player.sendPacket(Protocol.U_UNION_TRADE_ROUTE_OPEN, routeOpenResp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
